﻿

function validateDescription() {
    var decCtrl = document.getElementById("Description");
    decCtrl.value = encodeURI(decCtrl.value);
    return true;
}

var _prevAnswerButton = null;

function Answer(messageId, messageTreeId) {
    if (_prevAnswerButton != null)
        _prevAnswerButton.style.visibility = "visible";

    var strIds = "_" + messageId + "_" + messageTreeId;
    var blockItem = document.getElementById("AnswerBlock");
    var cellItem = document.getElementById("AnswerCellBlock" + strIds);
    _prevAnswerButton = document.getElementById("AnswerButton" + strIds);

    cellItem.appendChild(blockItem);

    _prevAnswerButton.style.visibility = "hidden";
    blockItem.style.display = "block";
    blockItem.style.visibility = "visible";

    var createCommentButton = document.getElementById("CreateCommentButton");
    createCommentButton.href = "javascript:AnswerExecute(" + messageId + "," + messageTreeId + ")";
}

function DeleteAnswer(messageId, messageTreeId) {
    var url = "/Comments/Delete?";
    url += "themeId=" + document.getElementById("ThemeIdCtrl").innerHTML;
    url += "&messageId=" + messageId;
    window.location.href = url;
}

function AnswerExecute(messageId, messageTreeId) {
    var url = "/Comments/Create?";
    url += "themeId=" + document.getElementById("ThemeIdCtrl").innerHTML;
    url += "&messageTreeId=" + messageTreeId;
    url += "&parentMessageId=" + messageId;
    if (messageTreeId == 0)
        url += "&text=" + encodeURI(document.getElementById("NewMessageText").value);
    else
        url += "&text=" + encodeURI(document.getElementById("MessageText").value);

    window.location.href = url;
}